package controller.utils;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

import entities.vo.ItemFacturaVO;

public class TableArticuloFacturaRender extends DefaultTableCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 496004518263459221L;

	@Override
	public Component getTableCellRendererComponent(JTable tabla, Object arg1,
			boolean arg2, boolean arg3, int row, int column) {
		Component component = super.getTableCellRendererComponent(tabla, arg1, arg2, arg3, row, column);
		ItemFacturaVO item = null;
		float precio=0;
		float precioActual =0;
		item = (ItemFacturaVO) ((DefaultTableModel)tabla.getModel()).getValueAt(row, 1);
		precioActual = (Float) ((DefaultTableModel)tabla.getModel()).getValueAt(row, 3);
		if((Boolean)((DefaultTableModel)tabla.getModel()).getValueAt(row, 3)){
			precio = item.getArticulo().getPrecioOferta();
		}else{
			precio = item.getArticulo().getPrecioUnitario();
		}
		if(precio!=precioActual){
			item.setPrecioCobrado(precio);
			((DefaultTableModel)tabla.getModel()).setValueAt(precio, row, 3);
		}
		return component;
	}

}
